package org.example;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        AirConditioner greeAirConditioner = new GreeAirConditioner();
        AirConditioner haierAirConditioner = new HaierAirConditioner();
        AirConditionerController controller = AirConditionerController.getInstance();
        AirConditionerOnState onState = new AirConditionerOnState();
        AirConditionerCleanState cleanState = new AirConditionerCleanState();
        AirConditionerDehumidificationState dehumidificationState = new AirConditionerDehumidificationState();
        AirConditionerOffState offState = new AirConditionerOffState();
        // 初始状态为关闭状态
        AirConditionerState currentState = offState;
        controller.addAirConditioner(greeAirConditioner);
        controller.addAirConditioner(haierAirConditioner);

        Scanner scanner = new Scanner(System.in);

        AirConditionerCommandInterpreter interpreter = new AirConditionerCommandInterpreter(greeAirConditioner);
        while (true) {
            System.out.println("===================================");
            System.out.println("功能清单:");
            System.out.println("1开启 2净化空气 3除湿 4设置温度 5关闭");
            System.out.println("请选择功能:");
            int opNum = scanner.nextInt();
            if (opNum == 1) {
                currentState.powerOn(controller, greeAirConditioner);
                currentState = onState;
            } else if (opNum == 2) {
                currentState.clean(controller, greeAirConditioner);
                currentState = cleanState;
            } else if (opNum == 3) {
                currentState.dehumidification(controller, greeAirConditioner);
                currentState = dehumidificationState;
            } else if (opNum == 5) {
                currentState.powerOff(controller, greeAirConditioner);
                currentState = offState;
                System.exit(0);
            } else {
                System.out.println("请输入想要设置的温度");
                int temperature = scanner.nextInt();
                String input = "set_temp " + temperature;
                // 解释用户命令并执行
                AirConditionerCommand command = interpreter.interpret(input);
                if (command != null) {
                    command.execute();
                } else {
                    System.out.println("无法解释命令");
                }
            }
        }
    }
}